package com.my.study.juc;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 写入时复制
 *
 * @author: yidujun
 * @create: 2021/03/16 15:57
 */
@Slf4j
public class CopyOnWriteTest {

    /**
     * 适用读多写少并发场景
     */
    @Test
    public void copyOnWriteListTest() {
        CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();
        list.add(3);
        int size = list.size();
        Integer integer = list.get(size - 1);
        System.out.println(integer);
    }

}
